unit UMovFolhaPagamentoItem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UModeloFilha, DB, DBTables, StdCtrls, Buttons, ExtCtrls,
  DBCtrls, Mask, ComCtrls, Grids, DBGrids;

type
  TFMovFolhaPagamentoItem = class(TFModeloFilha)
    dsCampos: TDataSource;
    Lb2: TLabel;
    dbedtEMPRESA: TDBEdit;
    Lb3: TLabel;
    dbedtCODEQUIPE: TDBEdit;
    Lb4: TLabel;
    dbedtPESCODIGO: TDBEdit;
    Lb6: TLabel;
    dbedtPESCOLSALARIO: TDBEdit;
    Lb7: TLabel;
    dbedtPESCOLSALARIOCARTEIRA: TDBEdit;
    Lb8: TLabel;
    dbedtTOTALINSS: TDBEdit;
    Lb11: TLabel;
    dbedtVALORDSR: TDBEdit;
    Lb13: TLabel;
    dbedtRECEBERBRUTO: TDBEdit;
    Lb15: TLabel;
    dbedtRECEBERLIQUIDO: TDBEdit;
    dbrgrpPESCOLPAGAINSS: TDBRadioGroup;
    EdDescEmpresa: TEdit;
    EdDescEquipe: TEdit;
    EdDescColaboradoor: TEdit;
    pgcFaltas: TPageControl;
    ts1: TTabSheet;
    ts2: TTabSheet;
    ts3: TTabSheet;
    DbgVale: TDBGrid;
    Dbg2: TDBGrid;
    Dbg3: TDBGrid;
    QFilhaEMPRESA: TIntegerField;
    QFilhaCODEQUIPE: TIntegerField;
    QFilhaPESCODIGO: TIntegerField;
    QFilhaPESCOLPAGAINSS: TStringField;
    QFilhaPESCOLSALARIO: TFloatField;
    QFilhaPESCOLSALARIOCARTEIRA: TFloatField;
    QFilhaTOTALINSS: TFloatField;
    QFilhaVALORDSR: TFloatField;
    QFilhaRECEBERBRUTO: TFloatField;
    QFilhaRECEBERLIQUIDO: TFloatField;
    QFilhaVALORHORAS50: TFloatField;
    QFilhaVALORHORAS100: TFloatField;
    QFilhaTOTALFALTAS: TFloatField;
    QFilhaVALE: TFloatField;
    QFilhaMESREFERENCIA: TIntegerField;
    QFilhaANOREFERENCIA: TIntegerField;
    Lb5: TLabel;
    dbedtMESREFERENCIA: TDBEdit;
    Lb9: TLabel;
    dbedtANOREFERENCIA: TDBEdit;
    dsVale: TDataSource;
    Lb1: TLabel;
    dbedtVALE: TDBEdit;
    ds2: TDataSource;
    DBCheckBox1: TDBCheckBox;
    procedure btnBtUltimoClick(Sender: TObject);
    procedure btnBtProximoClick(Sender: TObject);
    procedure btnBtAnteriorClick(Sender: TObject);
    procedure btnBtPrimeiroClick(Sender: TObject);
    procedure DbgValeCellClick(Column: TColumn);
    procedure DbgValeDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DbgValeColExit(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DbgValeKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  FMovFolhaPagamentoItem: TFMovFolhaPagamentoItem;

implementation

uses UMovFolhaPagamento;

{$R *.dfm}

procedure TFMovFolhaPagamentoItem.btnBtUltimoClick(Sender: TObject);
begin
 // inherited;
 FMovFolhaPagamento.QFolhaPagamentoItem.Last;
 FMovFolhaPagamento.QFolhaPagamentoItem.Edit;

end;

procedure TFMovFolhaPagamentoItem.btnBtProximoClick(Sender: TObject);
begin
//  inherited;
  FMovFolhaPagamento.QFolhaPagamentoItem.Next;
  FMovFolhaPagamento.QFolhaPagamentoItem.Edit;
end;

procedure TFMovFolhaPagamentoItem.btnBtAnteriorClick(Sender: TObject);
begin
//  inherited;
 FMovFolhaPagamento.QFolhaPagamentoItem.Prior;
 FMovFolhaPagamento.QFolhaPagamentoItem.Edit;
end;

procedure TFMovFolhaPagamentoItem.btnBtPrimeiroClick(Sender: TObject);
begin
 // inherited;
 FMovFolhaPagamento.QFolhaPagamentoItem.First;
 FMovFolhaPagamento.QFolhaPagamentoItem.Edit;
end;

procedure TFMovFolhaPagamentoItem.DbgValeCellClick(Column: TColumn);
var x:integer;
    SomaVale:Real;

begin
  inherited;

  SomaVale := 0;

 for x := 0 to DbgVale.SelectedRows.Count - 1 do
 Begin
   DbgVale.DataSource.DataSet.GotoBookMark(Pointer(DbgVale.SelectedRows[x]));
   SomaVale := SomaVale + DbgVale.Columns[2].Field.AsFloat;
 end;


 FMovFolhaPagamento.QFolhaPagamentoItem.FieldByName('VALE').AsFloat := SomaVale;


end;

procedure TFMovFolhaPagamentoItem.DbgValeDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
 DrawState: Integer;
  DrawRect: TRect;
begin
  if (gdFocused in State) then
  begin
    if (Column.Field.FieldName = DBCheckBox1.DataField) then
    begin
     DBCheckBox1.Left := Rect.Left + DbgVale.Left + 2;
     DBCheckBox1.Top := Rect.Top + DbgVale.top + 2;
     DBCheckBox1.Width := Rect.Right - Rect.Left;
     DBCheckBox1.Height := Rect.Bottom - Rect.Top;
     DBCheckBox1.Visible := True;
    end
  end
  else
  begin
    if (Column.Field.FieldName = DBCheckBox1.DataField) then
    begin
      DrawRect:=Rect;
      InflateRect(DrawRect,-1,-1);

      if Column.Field.Value = 'S' then DrawState := 1
      Else DrawState := 0;

      DbgVale.Canvas.FillRect(Rect);
      DrawFrameControl(DbgVale.Canvas.Handle, DrawRect,
        DFC_BUTTON, DrawState);
    end;
  end;
end;

procedure TFMovFolhaPagamentoItem.DbgValeColExit(Sender: TObject);
begin
  inherited;
  if DbgVale.SelectedField.FieldName = DBCheckBox1.DataField then
    DBCheckBox1.Visible := False
end;

procedure TFMovFolhaPagamentoItem.FormCreate(Sender: TObject);
begin
  inherited;
 DBCheckBox1.DataSource := dsVale;
 DBCheckBox1.DataField := 'DESCONTADOVALE';
 DBCheckBox1.Visible := False;
 DBCheckBox1.Color := DbgVale.Color;
 DBCheckBox1.Caption := '';
 //explicado mais adiante no artigo
 DBCheckBox1.ValueChecked := 'S';
 DBCheckBox1.ValueUnChecked := 'N';
end;

procedure TFMovFolhaPagamentoItem.DbgValeKeyPress(Sender: TObject;
  var Key: Char);
begin
  inherited;
  if (key = Chr(9)) then
    Exit;
  if (DbgVale.SelectedField.FieldName = DBCheckBox1.DataField) then
  begin
    DBCheckBox1.SetFocus;
    SendMessage(DBCheckBox1.Handle, WM_Char, word(Key), 0);
  end;
end;

end.
